<script setup lang="ts">
import type { NuxtError } from '#app'
import { useRouter } from 'vue-router'

const router = useRouter()
const props = defineProps({
  error: Object as () => NuxtError | undefined
})

const handleGoBack = () => {
  router.go(-1)
}
</script>

<template>
  <div class="error-container">
    <div class="error-card">
      <div class="error-status">
        <span v-if="error">{{ error.statusCode }}</span>
        <span v-else>404</span>
      </div>
      <h2 class="error-title" v-if="error?.statusMessage">
        {{ error.statusMessage }}
      </h2>
      <h2 class="error-title" v-else>
        页面未找到或发生错误
      </h2>
      <p class="error-message" v-if="error?.message">
        {{ error.message }}
      </p>
      <div class="error-actions">
        <button @click="handleGoBack" class="btn back-btn">
          返回上一页
        </button>
        <NuxtLink to="/" class="btn home-btn">
          返回首页
        </NuxtLink>
      </div>
    </div>
    <p class="support-text">
      如有疑问，请联系客服支持
    </p>
  </div>
</template>

<style scoped>
.error-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.error-card {
  background: #ffffff;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  padding: 40px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.error-card:hover {
  transform: translateY(-5px);
}

.error-status {
  font-size: 8rem;
  font-weight: bold;
  color: #e74c3c;
  margin: 20px 0;
  position: relative;
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.error-title {
  font-size: 1.8rem;
  color: #2c3e50;
  margin-bottom: 15px;
}

.error-message {
  color: #7f8c8d;
  line-height: 1.6;
  margin-bottom: 30px;
  padding: 15px;
  background-color: #f8f9fa;
  border-left: 4px solid #e74c3c;
}

.error-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 20px;
}

.btn {
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
  text-decoration: none;
}

.back-btn {
  background-color: #ecf0f1;
  color: #2c3e50;
}

.back-btn:hover {
  background-color: #bdc3c7;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.home-btn {
  background-color: #3498db;
  color: white;
}

.home-btn:hover {
  background-color: #2980b9;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.support-text {
  margin-top: 25px;
  color: #7f8c8d;
  font-size: 0.9rem;
  position: relative;
  animation: fadeIn 1s ease-in;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .error-status {
    font-size: 6rem;
  }
  .error-title {
    font-size: 1.5rem;
  }
  .error-actions {
    flex-direction: column;
  }
  .btn {
    width: 100%;
  }
}
</style>
